/**
 * @Author wangfan
 * @Date 2016/9/30 14:08
 */

package cn.ac.big.bigd.api.controller;


import cn.ac.big.bigd.bigsearch.ESFactory;
import cn.ac.big.bigd.bigsearch.Model.Entry;
import cn.ac.big.bigd.bigsearch.service.BigSearchService;
import cn.ac.big.bigd.dao.NewAssemblyDao;
import cn.ac.big.bigd.model.generate.NewAssembly;
import cn.ac.big.bigd.util.DateUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.elasticsearch.action.DocWriteResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("api/bigsearch")
public class BigSearchController {

    @Autowired
    NewAssemblyDao newAssemblyDao;
    @Autowired
    BigSearchService bigSearchService;


    @RequestMapping(value = "/saveAccession", method = RequestMethod.GET)
    public Object saveAccession(String accession) throws Exception {
        System.out.println(accession);
        if(bigSearchService.createGwhAccession(accession)){
            return accession;
        }else{
            return "error";
        }
    }





    @RequestMapping(value = "/removeAccession", method = RequestMethod.GET)
    public Object removeAccession(String accession) throws Exception {
        System.out.println(accession);
        String date = DateUtils.formatTime(new Date());
  /*      NewAssembly newAssembly = newAssemblyDao.findByAccession(accession);
        if(newAssembly==null){
            return  "no accession";
        }*/


        DeleteRequest request = new DeleteRequest(ESFactory.INDEX, "gwh_entry", accession);
        DeleteResponse deleteResponse = ESFactory.getClient().delete(request).actionGet();
        if (deleteResponse.getResult() == DocWriteResponse.Result.NOT_FOUND) {

        }

        return deleteResponse.getResult();


    }





}
